package com.ruoyi.fetv.controller.userController.school;

import com.ruoyi.common.aspect.annotation.AutoDict;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.exception.ServiceException;
import com.ruoyi.fetv.controller.userController.school.vo.RequestVO;
import com.ruoyi.fetv.controller.userController.school.vo.RespVO;
import com.ruoyi.fetv.domain.FetvSchool;
import com.ruoyi.fetv.service.IFetvSchoolService;
import com.ruoyi.fetv.util.Constant;
import com.ruoyi.fetv.util.Convert;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 高校Controller
 *
 * @author Jack
 * @date 2023-03-07
 */
@Api(value = "/v1/fetv/school", tags = {"用户获取高校信息"})
@RestController
@RequestMapping("/v1/fetv/school")
@Validated
@AutoDict
public class SchoolController extends BaseController {
    @Autowired
    private IFetvSchoolService fetvSchoolService;

    /**
     * 查询高校列表
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataTypeClass = RequestVO.class, name = "UserSchoolRequestVO", value = "学校参数", required = true)
    })
    @ApiOperation(value = "查询高校列表", notes = "查询高校列表", httpMethod = "GET")
    @ApiResponse(code = 200, message = "", response = TableDataInfo.class)
    @GetMapping("/list")
    public TableDataInfo<List<RespVO>> list(RequestVO requestVO) {
        startPage();
        FetvSchool fetvSchool = (FetvSchool) Convert.convert(requestVO, FetvSchool.class);
        fetvSchool.setStatus(Constant.ENABLE);
        List<FetvSchool> list = fetvSchoolService.selectFetvSchoolList(fetvSchool);
        Convert.covertList(list, FetvSchool.class, RespVO.class);
        return getDataTable(list);
    }

    /**
     * 获取高校详细信息
     */
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", dataType = "long", name = "id", required = true)
    })
    @ApiOperation(value = "获取高校详细信息", notes = "获取高校详细信息", httpMethod = "GET")
    @ApiResponses({
            @ApiResponse(code = 200, message = "", response = RespVO.class),
            @ApiResponse(code = 500, message = "请不要越权||不存在的ID", response = String.class)
    })
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        FetvSchool data = fetvSchoolService.selectFetvSchoolById(id);
        if (data == null) {
            throw new ServiceException("不存在的ID");
        }
        if (Constant.ENABLE.equals(data.getStatus())) {
            RespVO respVO = (RespVO) Convert.convert(data, RespVO.class);
            return success(respVO);
        }
        throw new ServiceException("请不要越权");
    }
}
